﻿using FirstFloor.ModernUI.Presentation;
using FirstFloor.ModernUI.Windows.Controls;
using FirstFloor.ModernUI.Windows.Navigation;
using LinnerToolkit.Desktop.ModernUI.Mvvm;
using LinnerToolkit.Desktop.ModernUI.Navigation;
using SimulationPTSystem.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace SimulationPTSystem.ViewModels
{
    public class TrainingSettingsPageViewModel : ModernViewModelBase
    {
        private List<TeamInfo> teamInfos;
        private TeamInfo selectedTeamInfo;

        public List<TeamInfo> TeamInfos { get => teamInfos; set => Set(ref teamInfos, value); }

        public TeamInfo SelectedTeamInfo { get => selectedTeamInfo; set => Set(ref selectedTeamInfo,value); }

        public ICommand StartCommand { get; }

        public TrainingSettingsPageViewModel(IModernNavigationService navigationService) : base(navigationService)
        {
            StartCommand = new RelayCommand((obj) =>
              {
                  if (SelectedTeamInfo == null)
                  {
                      ModernDialog.ShowMessage("请先选择团队", string.Empty, System.Windows.MessageBoxButton.OK);
                      return;
                  }

                  NavigateCommand.Execute(new NavigationPageParameter
                  {
                      PageKey = "TrainingPage",
                      Parameter = SelectedTeamInfo,
                  });
              });
        }

        public override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (e.NavigationType == NavigationType.New)
                Task.Run(async () =>
                {
                    TeamInfos = await SimulationPTDAL.GetTeamInfosAsync();
                });
        }
    }
}
